package com.hmall.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.common.dto.PageDTO;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.amqp.RabbitTemplateConfigurer;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Date;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {

    @Autowired
    private RabbitTemplateConfigurer rabbitTemplateConfigurer;

    @Override
    public PageDTO<Item> listByPage(int page, int size) {
        //构建分页条件
        IPage<Item> iPage = new Page<>(page,size);
        //构建查询条件
        LambdaQueryWrapper<Item> query = new LambdaQueryWrapper<>();
        //按照最后修改时间倒序排列
        query.orderByDesc(Item::getUpdateTime);
        IPage<Item> itemIPage = this.page(iPage,query);
        //构建相应对象
        PageDTO<Item> result = new PageDTO<>(itemIPage.getTotal(),itemIPage.getRecords());
        return null;
    }



    @Override
    public void add(Item item) {
        //添加创建时间和更新时间
        item.setCreateTime(new Date());//.sql? .util?
        item.setUpdateTime(new Date());
        //保存
        this.save(item);

    }

    @Override
    public void updateItem(Item item) {
        //修改更新时间
        item.setUpdateTime(new Date());//.sql??
        //执行更新
        this.updateById(item);

    }

    @Override
    public void deleteItem(Long id) {
        //删除
        this.removeById(id);

    }
}
